package com.zxl.diy.weather.location;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;

import com.mapbar.android.location.CellLocationProvider;
import com.zxl.manager.privacy.utils.ApplicationHelper;
import com.zxl.manager.privacy.utils.utils.NetUtils;

/**
 * Created by Administrator on 2016/11/5.
 */

public class CellLocationHelper extends BaseLocationHelper implements LocationListener {

    private CellLocationProvider mCellLocationProvider;

    public CellLocationHelper(Context mContext, OnLocationStatusListener mOnLocationStatusListener) {
        super(mContext, mOnLocationStatusListener);
        mCellLocationProvider = new CellLocationProvider(mContext);
        mCellLocationProvider.addLocationListener(this);
    }

    @Override
    public void startLocation() {
        super.startLocation();
        if (NetUtils.isNetWorkAvailable(ApplicationHelper.getContext())) {
            mCellLocationProvider.enableLocation();
        } else {
            onLocationFailed(OnLocationStatusListener.LOCATION_NETWORK_ERROR);
        }
    }

    @Override
    public void cancel() {
        mCellLocationProvider.disableLocation();
        super.cancel();
    }

    @Override
    public void onLocationChanged(Location location) {
        if (null != location) {
            super.onLocationSuccess(location);
        } else {
            super.onLocationFailed(LOCATION_NULL);
        }
        mCellLocationProvider.disableLocation();
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onProviderDisabled(String provider) {
    }
}
